package de.stalinski.login;

import de.stalinski.db.LoginDatabaseConnector;
import de.stalinski.logging.FrbrLogger;
import java.util.ArrayList;

public class LoginManager {
    
    private LoginDatabaseConnector ldbc = LoginDatabaseConnector.instance();
    private SessionCheck sessionCheck = SessionCheck.instance();
    private String user;
    private String pw;
    private String sessionID;
    private ArrayList<Client> sessionIDS = new ArrayList();

    public LoginManager() {

    }

    public void setSessionID(String id) {
        this.sessionID = id;
    }

    public String getSessionID() {
        return sessionID;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public void setPW(String pw) {
        this.pw = pw;
    }

    public String getPW() {
        return pw;
    }

    public String getUser() {
        return user;
    }

    public void updateSessionDuration(String sessionID) {
        sessionCheck.updateDuration(sessionID);
    }

    public boolean validSession(String user, String sessionID) {
        return sessionCheck.sessionActive(user, sessionID);
    }

    public boolean checkUser(String user, String pw, String sessionID) {
        boolean result = false;
        if(ldbc.doQuery(user, pw)) {
            result = true;
        }
        return result;
    }

    public void removeByIDandName(String user, String sessionID) {
        sessionCheck.removeFromList(user,sessionID);
        
    }

    public void add(String user, String sessionID) {
        sessionCheck.addToList(new Client(user,sessionID));
    }

    public boolean checkSession(String user, String sessionID) {
        return !sessionCheck.isAlreadyInList(new Client(user, sessionID));
    }

    public boolean isInactiveSession(String user, String sessionID) {
        return sessionCheck.checkInactivityFor(user, sessionID);
    }

}
